/**
 *
 */
package br.com.documentar.util;

import javax.swing.JDialog;

/**
 * Classe que gerencia a exibição de todos os log's gerados na aplicação
 */
public class TratadorExcessaoView extends JDialog {

    private String detalhes;

    /**
     * Metodo de arranque da Classe ErrosSistema
     */
    public TratadorExcessaoView() {
        initComponents();
        setAlwaysOnTop(true);
        setModal(true);
        setLocationRelativeTo(rootPane);
        requestFocusInWindow();
        jPanelDetalhes.setVisible(false);
        this.pack();
    }

    public void setDetalhes(String detalhes) {
        this.detalhes = detalhes;
    }

    public void setTextoArea() {
        this.jTextAreaDetalhes.setEditable(false);
        this.jTextAreaDetalhes.setText(detalhes);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSeparator1 = new javax.swing.JSeparator();
        jPanelReportarInconsistencia = new javax.swing.JPanel();
        jLabelReportarInconsistencia = new javax.swing.JLabel();
        jLabelMensagem1 = new javax.swing.JLabel();
        jToggleButtonDetalhes = new javax.swing.JToggleButton();
        jButtonEnviar = new javax.swing.JButton();
        jSeparatorReportarInconsistencia = new javax.swing.JSeparator();
        jLabel1 = new javax.swing.JLabel();
        jPanelDetalhes = new javax.swing.JPanel();
        jScrollPaneDetalhes = new javax.swing.JScrollPane();
        jTextAreaDetalhes = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Incosistência na Execução");
        setName("Reportar Inconsistência"); // NOI18N
        setResizable(false);

        jLabelReportarInconsistencia.setFont(new java.awt.Font("DejaVu Sans", 1, 36)); // NOI18N
        jLabelReportarInconsistencia.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabelReportarInconsistencia.setText("Inconsistência");
        jLabelReportarInconsistencia.setToolTipText("Reportar inconsistência");

        jLabelMensagem1.setText("Ocorreu uma excessão ao executar este processo. Ajude a melhorar o sistema enviado os detalhes.");

        jToggleButtonDetalhes.setText("Detalhes >>");
        jToggleButtonDetalhes.setToolTipText("Exibir os detalhes");
        jToggleButtonDetalhes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButtonDetalhesActionPerformed(evt);
            }
        });

        jButtonEnviar.setText("Enviar");
        jButtonEnviar.setToolTipText("Enviar detalhes");
        jButtonEnviar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEnviarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelReportarInconsistenciaLayout = new javax.swing.GroupLayout(jPanelReportarInconsistencia);
        jPanelReportarInconsistencia.setLayout(jPanelReportarInconsistenciaLayout);
        jPanelReportarInconsistenciaLayout.setHorizontalGroup(
            jPanelReportarInconsistenciaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelReportarInconsistenciaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelReportarInconsistenciaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jSeparatorReportarInconsistencia, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 749, Short.MAX_VALUE)
                    .addGroup(jPanelReportarInconsistenciaLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 439, Short.MAX_VALUE)
                        .addComponent(jToggleButtonDetalhes, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButtonEnviar, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanelReportarInconsistenciaLayout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(jLabelMensagem1, javax.swing.GroupLayout.DEFAULT_SIZE, 737, Short.MAX_VALUE)))
                .addContainerGap())
            .addGroup(jPanelReportarInconsistenciaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelReportarInconsistenciaLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jLabelReportarInconsistencia, javax.swing.GroupLayout.DEFAULT_SIZE, 749, Short.MAX_VALUE)
                    .addContainerGap()))
        );
        jPanelReportarInconsistenciaLayout.setVerticalGroup(
            jPanelReportarInconsistenciaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelReportarInconsistenciaLayout.createSequentialGroup()
                .addContainerGap(130, Short.MAX_VALUE)
                .addComponent(jSeparatorReportarInconsistencia, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelMensagem1)
                .addGap(38, 38, 38)
                .addGroup(jPanelReportarInconsistenciaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelReportarInconsistenciaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButtonEnviar, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jToggleButtonDetalhes, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
            .addGroup(jPanelReportarInconsistenciaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelReportarInconsistenciaLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jLabelReportarInconsistencia, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(138, Short.MAX_VALUE)))
        );

        jPanelDetalhes.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Detalhes", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 14))); // NOI18N
        jPanelDetalhes.setEnabled(false);

        jTextAreaDetalhes.setColumns(20);
        jTextAreaDetalhes.setRows(5);
        jTextAreaDetalhes.setBorder(null);
        jScrollPaneDetalhes.setViewportView(jTextAreaDetalhes);

        javax.swing.GroupLayout jPanelDetalhesLayout = new javax.swing.GroupLayout(jPanelDetalhes);
        jPanelDetalhes.setLayout(jPanelDetalhesLayout);
        jPanelDetalhesLayout.setHorizontalGroup(
            jPanelDetalhesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDetalhesLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPaneDetalhes, javax.swing.GroupLayout.DEFAULT_SIZE, 737, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanelDetalhesLayout.setVerticalGroup(
            jPanelDetalhesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelDetalhesLayout.createSequentialGroup()
                .addComponent(jScrollPaneDetalhes, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanelReportarInconsistencia, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanelDetalhes, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanelReportarInconsistencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelDetalhes, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        getAccessibleContext().setAccessibleDescription("Reportar inconsistência");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonEnviarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonEnviarActionPerformed
        try {
            dispose();
        } catch (Exception ex) {
            setDetalhes(getClass().getName() + "\nERRO: " + ex.getMessage());
            dispose();
        }
}//GEN-LAST:event_jButtonEnviarActionPerformed

    private void jToggleButtonDetalhesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButtonDetalhesActionPerformed
        if (jToggleButtonDetalhes.isSelected()) {
            jPanelDetalhes.setVisible(true);
            this.pack();
        } else {
            jPanelDetalhes.setVisible(false);
            this.pack();
        }
        setTextoArea();
}//GEN-LAST:event_jToggleButtonDetalhesActionPerformed

    public static void main() {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TratadorExcessaoView().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonEnviar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabelMensagem1;
    private javax.swing.JLabel jLabelReportarInconsistencia;
    private javax.swing.JPanel jPanelDetalhes;
    private javax.swing.JPanel jPanelReportarInconsistencia;
    private javax.swing.JScrollPane jScrollPaneDetalhes;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparatorReportarInconsistencia;
    private javax.swing.JTextArea jTextAreaDetalhes;
    private javax.swing.JToggleButton jToggleButtonDetalhes;
    // End of variables declaration//GEN-END:variables
}
